{template 'common/header'}
<link rel="stylesheet" type="text/css" href="../addons/{php echo $_GPC['m']}/resource/css/style.css" />
<link rel="stylesheet" type="text/css" href="../addons/{php echo $_GPC['m']}/resource/swal/dist/sweetalert2.min.css" />
<style>
    .right-content{
        max-width: 988px;
        box-sizing: border-box;
    }
</style>
<div id="shop2" data-store="" data-name="" style="display: none;"></div>
<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">
            用户列表
        </h3>
    </div>
    <div class="panel-body">
        <div class="ibox-content">
            <form action="{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'version_id'=>$_GPC['version_id'])}" id="searchform" method="get">
                <input type="hidden" class="form-control" name="c" value="site">
                <input type="hidden" class="form-control" name="a" value="entry">
                <input type="hidden" class="form-control" name="do" value="{$_GPC['do']}">
                <input type="hidden" class="form-control" name="m" value="{$_GPC['m']}">
                <input type="hidden" class="form-control" name="version_id" value="{$_GPC['version_id']}">
                <div class="row" style="padding: 0 15px;">
                    <div class="col-sm-3">
                        <input type="text" class="form-control" placeholder="用户id" name="openid" value="{$openid}">
                    </div>
                    <div class="col-sm-3">
                        <input type="text" class="form-control" placeholder="昵称" name="nick" value="{$nick}">
                    </div>
                    <div class="col-sm-2">
                        <button type="submit" class="btn btn-default " style="margin-right:5px;">查询</button>
                    </div>
                </div>
            </form>
        </div>
        <form action="" method="post" class="form-horizontal form">
            <input type="hidden" name="token" value="{$_W['token']}">

            <div class="table-responsive panel-body">
                <table class="table-striped table-bordered table-hover dataTables-example table">
                    <thead class="navbar-inner">
                    <tr>
                        <th>用户id</th>
                        <th>头像</th>
                        <th>昵称</th>
                        <th>管理中心</th>
                        <th>添加时间</th>
                        <!--<th style="text-align: right;">操作</th>-->
                    </tr>
                    </thead>
                    <tbody id="level-list">
                    {loop $list $index $item}
                    <tr>
                        <td><div class="type-parent">{$item['openid']}</div></td>
                        <td><div class="type-parent"><img src="{php echo tomedia($item['avatar']);}" width="50" height="50"/></div></td>
                        <td><div class="type-parent">{$item['nick']}</div></td>
                        <td id="shop_admin">
                            <div class="btn-group">
                                <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                    {$item['shop_name']}<span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu" data-id="{$item['id']}">
                                    <li data-level="-1"><a href="javascript:;">无权限</a></li>
                                    <li data-level="1"><a href="javascript:;">管理员</a></li>
                                    <li data-level="2" data-toggle="modal" data-target="#sort_link" data-type="shop"><a href="javascript:;">子管理员</a></li>
                                </ul>
                            </div>
                        </td>
                        <td><div class="type-parent">{$item['createtime']}</div></td>
                        <!--<td style="text-align: right;">-->
                            <!--{if $item['shop']==1}-->
                            <!--<a class="btn btn-danger btn-xs edit" data-id="{$item['id']}" data-status="-1"><i class="fa fa-edit"></i>解绑</a>-->
                            <!--{else}-->
                            <!--<a class="btn btn-primary btn-xs edit" data-id="{$item['id']}" data-status="1"><i class="fa fa-edit"></i>绑定</a>-->
                            <!--{/if}-->
                        <!--</td>-->
                    </tr>
                    {/loop}
                    </tbody>
                </table>
                <div style="text-align: right;">
                    {$pager}
                </div>
            </div>
        </form>
    </div>
</div>
<div class="modal fade" id="sort_link"><div class="modal-dialog">
    <style>
        #sort_link .modal-body {padding: 10px 15px;}
        #sort_link .tab-pane {margin-top: 5px; min-height: 400px; max-height: 400px; overflow-y: auto;}
        #sort_tab{margin-bottom: 10px;}
    </style>
    <div class="modal-content">
        <div class="modal-header">
            <button data-dismiss="modal" class="close" type="button">×</button>
            <h4 class="modal-title">绑定校区</h4>
        </div>
        <div class="modal-body">
            <iframe width="100%" height="395" frameborder="no" border="0" scrolling="no" allowtransparency="yes" src="{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'service')}"></iframe>
        </div>
        <div class="modal-footer">
            <button data-dismiss="modal" class="btn btn-default" id="sort_close" type="button">关闭</button>
        </div>
        <script>
            var sort_objc='';
            $(function(){
                $(".sort_customize").on('click','.sort_link',function(){
                    var id=$(this).attr("data-id");
                    if(id==2){
                        $("#sort_link").find("#sort_tab li").eq(1).hide();
                    }else{
                        $("#sort_link").find("#sort_tab li").eq(1).show();
                    }
                    sort_objc=this;
                });
                $("#sort_link").find('#sort_tab a').click(function(e) {
                    $('#tab').val($(this).attr('href'));
                    e.preventDefault();
                    $(this).tab('show');
                });
            });
        </script>
    </div>
</div></div>
<script>
    require(["../addons/{php echo $_GPC['m']}/resource/swal/dist/sweetalert2.min.js"],function(){
        var objc="";
        $(function(){
            //改变状态
            $(".edit").click(function(){
                var status=$(this).attr("data-status");
                var that=$(this);
                var id=$(this).attr("data-id");
                $.ajax({
                    type:"post",
                    url:"{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'statuschange','version_id'=>$_GPC['version_id'])}",
                    data:{id:id,status:status},
                    dataType:'json',
                    success:function(res){
                        if(res.status==1){
                            swal('操作成功!', '操作成功!', 'success');
                            if(status==1){
                                that.html("解绑");
                                that.attr("data-status",-1);
                                that.removeClass("btn-primary").addClass("btn-danger");
                                that.parent().prev().prev().find("a").html('已绑定');
                            }else{
                                that.html("绑定");
                                that.attr("data-status",1);
                                that.addClass("btn-primary").removeClass("btn-danger");
                                that.parent().prev().prev().find("a").html('未绑定');
                            }
                        }else{
                            swal('操作失败!', '操作失败!', 'error');
                        }
                    }
                })
            })
            //删除
            $(".delete").click(function(){
                var that=$(this);
                var id=$(this).attr('data-id');
                swal({
                    title: '确定删除吗?',
                    text: "确定删除吗?",
                    type: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: '删除',
                    cancelButtonText: '取消',
                }).then(function(isConfirm) {
                    if (isConfirm) {
                        $.ajax({
                            type:"post",
                            url:"{url 'site/entry/banner',array('m'=>$_GPC['m'],'op'=>'delete','version_id'=>$_GPC['version_id'])}",
                            data:{id:id},
                            dataType:'json',
                            success:function(res){
                                if(res.status==1){
                                    swal('操作成功!', '操作成功!', 'success');
                                    that.parent().parent().remove();
                                }else{
                                    swal('操作失败!', '操作失败!', 'error');
                                }
                            }
                        })
                    }
                })
            });
            //商家中心
            $("#shop_admin .dropdown-menu li").click(function(){
                var level=$(this).attr("data-level");
                if(level!=2){
                    var id=$(this).parent().attr("data-id");
                    var that=this;
                    $.ajax({
                        type:"post",
                        url:"{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'shop','version_id'=>$_GPC['version_id'])}",
                        data:{id:id,shop:level},
                        dataType:'json',
                        success:function(res){
                            if(res.status==1){
                                swal('操作成功!', '操作成功!', 'success');
                                if(level==-1){
                                    $(that).parent().prev().html('无权限<span class="caret"></span>');
                                }else if(level==1){
                                    $(that).parent().prev().html('管理员<span class="caret"></span>');
                                }
                            }else{
                                swal('操作失败!', '操作失败!', 'error');
                            }
                        }
                    })
                }else{
                    objc=this;
                }
            });
            $("#shop2").click(function(){
                var store=$(this).attr("data-store");
                var name=$(this).attr("data-name");
                if(store!="" && name!=""){
                    var id=$(objc).parent().attr("data-id");
                    $.ajax({
                        type:"post",
                        url:"{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'shop','version_id'=>$_GPC['version_id'])}",
                        data:{id:id,shop:2,shop_id:store},
                        dataType:'json',
                        success:function(res){
                            if(res.status==1){
                                swal('操作成功!', '操作成功!', 'success');
                                $(objc).parent().prev().html(name+'<span class="caret"></span>');
                            }else{
                                swal('操作失败!', '操作失败!', 'error');
                            }
                        }
                    })
                }
            });
        })
    })
</script>
{template 'common/footer'}